package com.example.togetherutils;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class ReturnInfo<T> {
    private int code;
    private String msg;
    private T data;

    public static <T> ReturnInfo<T> success() {
        return ReturnInfo.<T>builder()
                .code(200)
                .msg("成功")
                .data(null).build();
    }

    public static <T> ReturnInfo<T> success(T data) {
        return ReturnInfo.<T>builder()
                .code(200)
                .msg("成功")
                .data(data)
                .build();
    }

    public static <T> ReturnInfo<T> fails(String msg) {
        return ReturnInfo.<T>builder()
                .code(500)
                .msg(msg)
                .data(null)
                .build();
    }

    public static <T> ReturnInfo<T> fails(int code, String msg) {
        return ReturnInfo.<T>builder()
                .code(code)
                .msg(msg)
                .data(null)
                .build();
    }
}
